

var mediaLogined = {
    nav: function() {
        $('.drap').on('click', function() {
            var $this = $(this);
            if($this.attr('data-status') == 0) {
                $this.next('ul').slideDown();
                $this.attr('data-status', 1);
                $this.addClass('ext-down');
            } else {
                $this.next('ul').slideUp();
                $this.attr('data-status', 0 );
                $this.removeClass('ext-down');
            }
        })
    },
    proveince: function() {
        var citySelect = $("#citySelect");
        if(citySelect.length) {
            citySelect.citySelect();
        }
    },
    setNavActive: function() {
        var navArr = ['weixin-show', 'sina-show', 'wanghong-show', 'video-show', 'headline-show', 'company-edit', 'user-center'];
        var href = window.location.href;
        $.each(navArr, function(index, item) {
            if(href.indexOf(item) != -1) {
                $('[data-role="'+item+'"]').addClass('is-active');
            }
        })
    },
    sinaLogin: function() {
        $('[data-role="sina-login"]').on('click', function() {
            $.ajax({
                url: window.domain + window.requestUrl.sinaloginUrl,
                type: 'get',
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                success: function(res) {
                    if(typeof(res.not_login) != 'undefined') {
                        window.setCookie('go_back_link', window.location.href);
                        window.location.href = './login.html';
                        return;
                    }
                    if(res.status) {
                        window.location.href = res.data.result;
                    } else {
                        iosOverlay({
                            text: res.msg,
                            duration: 1000
                        });
                    }
                },
                error: function(e) {
                }
            })
        })
    },
    init: function() {
        this.nav();
        this.setNavActive();
        this.proveince();
        this.sinaLogin();
    }
}
mediaLogined.init();
